package com.lyf.controller;
import com.lyf.entity.Payment;
import com.lyf.entity.ResponseResult;
import com.lyf.dao.PaymentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @AUTHOR LYF
 * @DATE 2022/2/5
 * @VERSION 1.0
 * @DESC
 */
@RestController
public class PaymentController {
    @Autowired
    PaymentDao paymentDao;
    @Value(value = "${server.port}")
    private String serverPort;

    @PostMapping("/payment/create")
    ResponseResult<Payment> createPayment(Payment payment){//不加 @RequestBody,否则为空
        // 处理空参数问题...
        int rs =  paymentDao.create(payment);
        if(rs==1){
            return new ResponseResult<>(200,"创建成功:serverPort:"+serverPort,payment);
        }else{
            return new ResponseResult<>(500,"创建失败",null);
        }
    }
    @GetMapping("/payment/get/{id}")
    ResponseResult<Payment> getPaymentById(@PathVariable(name = "id") Long id){
        System.out.println("进入controller...id:"+id);
        Payment payment = paymentDao.getById(id);
        return new ResponseResult<>(200,"查询成功:serverPort:"+serverPort,payment);
    }
}
